﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using UTable.Input;
using UTable.Input.MultiTouch;
using UTable.Objects;
using UTable.Objects.Controls;
using System.Drawing;
using Point = System.Windows.Point;
using System.Windows.Media;
using System.Windows.Shapes;
using UTable.Objects.Handlers.Gestures;

namespace UTable.Tests
{
    /// <summary>
    /// Interaction logic for TestObject.xaml
    /// </summary>
    public partial class TestObject : UObject
    {
        private Point currentPoint;

        public TestObject()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Window_Loaded);
            //LocalGestureEngine engine = new LocalGestureEngine(this, this);
            //OneContactGestureRecognizer recognizer1 = new OneContactGestureRecognizer();
            //recognizer1.EnabledGestures.Add(OneContactGestureType.Tap);
            //engine.RegisterGesture(recognizer1);
            //engine.GestureDetected += new GestureDetectedEventHandler(OnGestureDetected);
            //this.MultiTouchProcessor.Handlers.Add(engine);
        }

        void OnGestureDetected(GestureRecognizer sender, GestureDetectedEventArgs args)
        {
            Console.WriteLine(args.DetectedGesture.ToString());
            sender.GestureEngine.StopRouteDown = false;
            sender.GestureEngine.HandleAllEvents = false;
        }

        private void Window_Loaded(object sender, RoutedEventArgs args)
        {
        //    UWarnDialog.Show(this as IObject, "test");
            //World.IsSelected = true;
            Polygon polygon = new Polygon();
            
            //rec.InputReceived += new InputEventHandler(rec_InputReceived);
        }

        private void rec_InputReceived(InputEventArgs args)
        {
            //FingerEventArgs fingerArg = (args as MultiTouchEventArgs).FingerEvents[0];
            //Console.WriteLine(fingerArg.EventType);

            //switch (fingerArg.EventType)
            //{
            //    case FingerEventType.FINGER_DOWN_EVENT:
            //        currentPoint = fingerArg.Position;
            //        break;
            //    case FingerEventType.FINGER_MOVE_EVENT:
            //        Point moveDistance = new Point(fingerArg.Position.X - currentPoint.X, fingerArg.Position.Y - currentPoint.Y);
            //        if ((int)moveDistance.X == 0 && (int)moveDistance.Y == 0) break;
            //        Console.WriteLine("{0} {1}", (int)moveDistance.X, (int)moveDistance.Y);
            //        Console.WriteLine("{0} {1}", rec.X, rec.Y);
            //        TranslateTransform translate = new TranslateTransform(moveDistance.X, moveDistance.Y);
            //        rec.RenderTransform = translate;
            //        //translate.BeginAnimation(TranslateTransform.XProperty, translate.X);
            //        //translate.BeginAnimation(TranslateTransform.XProperty, translate.X);
            //        Console.WriteLine("{0} {1}", rec.X, rec.Y);
            //        currentPoint = fingerArg.Position;
            //        break;
            //}
            ////rec.X = (args as MultiTouchEventArgs).FingerEvents[0].EventType = FingerEventType.FINGER_UP_EVENT
            //Console.WriteLine(args.GetType());
            //args.Handled = true;
            //args.RouteDown = false;
        }

        private void Press(object sender, ButtonEventArgs args)
        {
            //UStackPanel panel = (UStackPanel)(sender as UImageButton).Content;
            //string ans = "";
            //foreach (object obj in panel.Children)
            //{
            //    ans += obj.ToString() + "\n";
            //    if (obj is UTextBlock)
            //    {
            //        Console.WriteLine("text is {0}", (obj as UTextBlock).Text);
            //        ans += (obj as UTextBlock).Text;
            //    }
            //    else
            //    {
            //        Console.WriteLine("source is {0}", (obj as UImage).Source);
            //        ans += (obj as UImage).Source;
            //    }
            //}
            //UWarnDialog.Show(ans);
        }
    }
}
